package com.fast.develop.dm.core.vo;


import java.io.Serializable;
import java.util.List;

/**
 * @author 莫寅
 * @createTime 2022-06-05 18:41
 * @desc：
 */
public class ResourcesVo<T> implements Serializable {

    Embedded _embedded;

    Page page;

    public ResourcesVo(Embedded _embedded, Page page) {
        this._embedded = _embedded;
        this.page = page;
    }

    public ResourcesVo(com.fast.develop.dm.core.data.Page page){
        long total = page.getTotal();
        int pageSize = page.getPageable().getPageSize();

        Page _page = new Page();
        _page.setSize(page.getTotal());
        _page.setTotalElements(pageSize);
        _page.setNumber(page.getPageable().getPageNumber());

        long totalPages = total/pageSize;
        if(total % pageSize != 0){
            totalPages++;
        }

        _page.setTotalPages(totalPages);

        this.page = _page;
        this._embedded = Embedded.Of(page.getContent());
    }

    private static class Embedded<T>{
        List<T> list;

        public Embedded(List<T> list) {
            this.list = list;
        }

        public static Embedded Of(List list){
            return new Embedded(list);
        }

        public List<T> getList() {
            return list;
        }

        public void setList(List<T> list) {
            this.list = list;
        }
    }

    class Page{
        private long size;
        private int totalElements;
        private long totalPages;
        private int number;

        public long getSize() {
            return size;
        }

        public void setSize(long size) {
            this.size = size;
        }

        public int getTotalElements() {
            return totalElements;
        }

        public void setTotalElements(int totalElements) {
            this.totalElements = totalElements;
        }

        public long getTotalPages() {
            return totalPages;
        }

        public void setTotalPages(long totalPages) {
            this.totalPages = totalPages;
        }

        public int getNumber() {
            return number;
        }

        public void setNumber(int number) {
            this.number = number;
        }
    }

    public Embedded get_embedded() {
        return _embedded;
    }

    public void set_embedded(Embedded _embedded) {
        this._embedded = _embedded;
    }

    public Page getPage() {
        return page;
    }

    public void setPage(Page page) {
        this.page = page;
    }
}
